package org.coursera.codebreak;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class GNomePattern {

	public static void main(String[] args) {
		GNomePattern gnp = new GNomePattern();
		//gnp.showLocation("datasource/Vibrio_cholerae.txt", "CTTGATCAT");
		//System.out.println();
		//gnp.showLocation("datasource/Vibrio_cholerae.txt", "ATGATCAAG");
		//gnp.showLocation("datasource/challenge-004-patternloc.txt", "AGACTTGAG");
		//gnp.showLocation("datasource/Thermotoga-petrophila.txt", "ATGATCAAG");
		//gnp.showLocation("datasource/Thermotoga-petrophila.txt", "CTTGATCAT");		
		//gnp.showLocation("datasource/oric/Thermotoga-petrophila.txt", "AAACCTACC");
/*		
		String[] data = {"GCTACGGAT","CCTTACAAG","TGCGTTCAC","CCGACATTA","TCACGGTCT","GATACCCCA","GTCATCCTG","GCAACGGCT","TGCGGCGCG","GGCGGTGAG","CGATGCCTG","GGTGGGGGA","GACGCGTTA","CCGCAACAA","TGGTGGGGG","TACGAGCTC","TACCGCTTG","TTTAAATAT","CGCAATAGC","CGCGAGCGC","CGCTGTCGC","GCGTAGCGC","TCGTCGGGC","CGAATCCTG","CCGCCGAAG","GCCGCCAGT","GATTCGAAC","TCGATCCGC","CGCTCACTG","TGGCGCGTC","TCTCTCGCT","ATATTTTTT","AGCTACGGA","ATTACTCAG","TCCGCCACC","CAGGAGTTA","CAAAGCGCG","GCGTAAACG","TCGAAGCTT","GGATGCGCT","GGCCTGATA","TGCCTTACC","AGGCTAATG","CACTGTAGG","CGTGATTTT","TAACCCGAA","GCGAGCGCC","GCGTCTTAT","GTAGGCCTG","GCACAATGC","ATCGCATCC","GACATCAAC","AACCGATGC","AGGTCGGAT","GTCGGATGC","CTACTAAAG","GTTTTTACG","ATCGTTTGA","CCGCAGGCG","AGGTCGGGG","GTGCCTTAC","CTTTAAATA","CCAGCTGAG","TTATCCGGC","GTCGATCCG","GCCTACACC","ATACCCCAA","CTTTGCTTA","ACCTACGGT","CATAACCCG","GTCTGTCCA","CCCGTAGGT","TTCCGGGTA","GGTGCATCC","TGTGCCGCA","TTTGGCAAC","CGACCTGTA","CTCATCCTT","GGCTTCTCA","ACTGCGTTC","ACATCTAAC","TCGATCCCG","AATAGCCTG","CCCGGTCGG","GCTCTTCTT","GTCGGGCTC","TCAGGCATC","TTTCTTTTG","GCCTACAAA","CAACGGTGG","AACCCGCCG","GCCTACAAC","CACCTTCGC","TGCGCGCTT","AACGCGTCT","AGTGCTCCA","CCTGAAGCT","GCGAGTTCG","TGCCTGATG","TCAATGCCT","GGATGCGGC","AAAGCAGAA","TTTGTAGGT","CGTAGGCCG","GCCGTCGAA","TCAGGCATT","AGGATTCGA","TAGCTCAGT","GGGGAAGGA","AAACCCGCC","AATTCCGCC","CTGCGTTCA","AAGATGCGC","TATCCCCGC","GTCGGGGTC","TTTGTAGGC","AAGGTCGGG","TAGCTCAGC","CTCACTGCG","CTCCACCCC","TCGTAGCCG","GTTGACTTT","GCACTGAAC","TCGGTTTAT","CCTACGGGG","GACGCGGGG","CTGCGGCAA","GACCCACCA","CACTATGGC","CACGACCTT","CTGAAAGAA","AAAAAAAGC","AAGCGTCGC","GATAAGATG","ACGCGTCTT","AAACTGGCA","ACGGTCTGT","CCGCTGGCG","GTCGGATAA","TGACGCGAC","TTATCCCCG","CAGTTGGCG","TGGCACTAT","CATGCCGAC","ACACTAACA","CTCATAACC","AGGCAGTCG","GCCAAGGTC","AGGCCTACA","AGGCCTACG","ACAGCGTCG","TTTACCGCT","TATCAGGCC","GAAGCGGGT","GCGGCAACG","AGCCCGCTC","GTTGCCAGG","AAATCCGGC","GTTTGGCAA","GATTTAGCG","TGTAGGCCT","CGGATAAGG","CGGATAAGA","AGTCGGCAC","TTGAAAGTG","CCTGCGGCA","TGCCCCTCC","TGGCTGGGG","GGTTTTTAC","CAGCCGCAA","TCGTGGACA","GCGCTTCGC","GGCATCTGC","ACCGATAAG","CGTGAACGC","CCGGACGGT","GTGTGTGCA","CTATGGCAC","AATGCCTGA","ACCGCTACT","TCGGGGTCG","ATGGTGGTG","TCACGACGT","GAGATGGTG","CAACCGGTT","CAGGCCTAC","GGGGAACAC","GAGCAGCCT","AGCCGCTTT","CCGATAAGC","TTTCAATAT","TCGGATAAG","GCCTTACCG","AAGGATTAC","TTATGCCGC","GAGCACCTC","CGCCGCAGC","CGGTTCGAT","TTCAAATCC","TGCCGGATG","CTGCCGGAT","GCTGACGCC","TGCGCTTTG","CATCATCAT","ATAATCTAC","GCTGACGCG","GGTTAACAA","GAACAGCAA","GAAGGTCGT","AGATGGGAG","ACGTCCGTA","AGTCATCCT","ATGAAATTT","GTCGCATCA","GTAGGCCGG","TGCCAAGGT","ATAAGACGC","CCTACGGAG","CCTGCGGGC","CCGGCCTAC","TTCACGCCG","TCGAGTCTC","CGCTGGCGC","GTCGCATCC","TATGGCGGT","TTATCAGGC","ATTAGCTCA","ATCACCCAC","ATGCGACGC","ATCGGCATC","GCCGACCAG","GTTTATGCC","TGAACTGGC","GGCTGGGGT","GCGCGGGGA","GGCAGTCGG","CCTACGGAT","CTGGGAGAG","TCCTTCCCC","GGTCGCGAG","CAGCTGAGC","TTTGTGCTG","TGCGGCGTG","GTTGCCTGA","GGGGCAAAA","TGCGGCGTA","GGCGCTGGA","GGGAACTCG","GGCGCTGGC","GGAGGATTC","TTGCCTGAT","GAGATGGGA","TCATAACCC","CAGCGCAAT","TGCTCCCTT","CCGACATCA","GTTGCCTGC","CCGACATCC","CGGGTTTTT","TTGCCTGCG","GATTACTCA","AATCCTGCA","CAGAATATT","GTCTCGTTT","GGGAACTCT","TTTCCCGCT","TCGGGTCGT","GAGTCATCC","ATCGCAGCG","CGCCGCATC","TTACGCCGC","ATCTAACGC","TTAATCAAT","GCAAAGCCG","CTCGGTTCG","GGCGTAAAC","GACAACCGA","TCGGAAAGC","CCGGATGCG","TACCGCTAC","TCTAACGCC","ACCGTAGGC","GGGTCGCGA","TCGAAGCCG","GCCTGCGGC","GCCGAGGAT","TCATCACCC","GGGGCTTCT","AAATATGGC","AAGAACAGG","GAATCTGTA","TCAGGCAGT","GTCTTCAAT","AAGGTCGTC","AAGAACAGC","ATTTTGTAG","GTTGGCGCA","GAGCTCTTC","CGGTTGCGC","TAAATAATC","CGTTTATGC","CGTCGAAGC","GCGCGCTTC","CGAAGCGGG","CTGTTCATA","CAGAAGAAC","AGTTTGGCA","AGCTGCAGC","TTCTTTTGG","TCTGTAGGC","CCCACGTCC","AAAAAGCCC","AAAAAGCAG","TCAGGCAAC","CATCTAACG","GCTGCGCGC","GGCGCTGCT","TTCATCTTT","GTGAGGGGG","GCCCTTCGG","AACAGGTCG","CAGCGCACC","GATGCATCG","GGTGAGGGG","GCAACAACC","GCTGGCAGT","GGAATGCCG","GCCCCCGCA","TAGCGCGTC","GCGACGCTT","GGCAGCCCG","GCCTGCGCC","GAACCGTAG","TTTTGAAAG","CAATAGCCT","CTAACGCCC","CGATCCGCG","CATCACCCA","GCACTATGG","CCGCTTTCT","AAAAAGCCG","GCGACGCTG","AATAATCTA","GTCTTATCA","GCAGAAGCA","TTACGCGTC","TCCCGCTCC","AGGCAACGG","TGAAACTGA","GGCAGGAAG","GGGTCGGCG","TGGCGCTGC","ACGACTGCC","CCGCCACCT","ACATTATTG","GGAATAGCT","GGTTCGATC","CAATTCCGC","CACTGCGTT","CCTACAAAA","GGACGGTGC","GAACTGGAA","CCCGGTGTG","CAGTTGGTA","ATCTATTCA","GCTTCGCTC","AGCGTAGCG","GCTTCGCCC","CACTAACAC","ATTTGTAGG","TTGATACCG","CGCTGATTG","CATTACGCG","GTAGCTCGT","GTAGCCGAG","CCAGCAGGC","ATGCCTACA","GGTCGATCC","GGAATTTGT","GGCGCGGGG","CGGCTGCCG","CCAGCAGCA","TGCGTATCG","CTCCAAAAG","CTACGGATG","ACTGGAGTT","ATCTTTCTG","GTTCGTAGC","CTGCACGAC","GTGGAGCAG","GATTGACTC","GTGCACTGA","CAGCAGGCC","ACGCGGGGT","CGCATAGCG","GAAGAACAG","TGTGCCGAA","GGGGGGGGA","GCTCAGTTG","ACGAAAAAA","ACACCGCTG","CCAACTGGC","TGAGCTACG","CCGCTATTG","ATAGCGTCG","GGTAGCTCG","CAGCCCGCT","ACGCGACTT","GGGCTCATA","CGGTGCTAC","TGTCGGATG","TTGGTGCGA","CCTACGGTT","GAACGCCTT","AGGTGAAAC","CAGTTGTCG","CCCTTACAA","CCCGAAGGT","TCAGTTGGT","GGTGCACTG","GCCACCTTC","CCTACGCCA","AGCGGCTGC","GTGAACGCC","TTCACGGTC","GCTTTGTTG","CTCTATCCA","CGAAGCCGC","CGTTCTTTA","GGTGAAACT","GCTGTGAAG","GCAGGAAGG","AACCGTAGG","GGGGGGGAC","CTACACCGC","AGGTGGGTC","GGCCCCCGC","AAAATATTT","CCGCATCCG","GCGCCTTAT","GGGGGGGAT","CGGGCTCAT","CACGGTCTG","GCCGCTGAC","AATATGGCG","TGGTGCGAG","GGTTGCCTG","ACAACCGGT","CACAGCGTC","GGTGCGAGG","CACGACCCA","CTGGAGTTT","ATCCCCCCG","CGGTTGCCT","TACGGAGGG","AGTTGGTAG","CAATTGGTC","AACTGGCTG","GACCGATAA","GTGGGGGAA","TCGCCCTGC","CGTCTTATC","TCGCGTCTT","CGCGAGTTC","CCTACAACT","AATAGCTCA","ACAAAATCG","ACTCTATCC","CGGTTCGTA","CTGGCTGTC","ACTGAACTG","TTCTGCCCC","TTCGCCCTT","CCGTCGAAG","TGGCTGTCG","CTGCGCACG","ATGCATCGG","CGCTCGGCA","AAGGCACTT","GACTGCCGG","AGGGTGCGG","TCGCCCTTC","CACTTGTGC","AGCCGCTAT","AAAAATTGA","AGCCTGATT","GCATCAGGC","CTTGCCAAG","GCAGCCCGC","CAGGCAACG","AAGCTTCTC","TGTGCAATA","TGTCCAACT","GGGGTCGCG","TGGTGCATC","TAGCCTGAT","TCCGGCAGT","CTGTCGCCA","AGCCGAGTA","TGGAACAGC","GGTTTATCC","CGGCAGTTG","ATAGCCTGA","CGCTTCACC","AAGTGATGG","CGAGTCTCG","AGAATATTT","ATAAGCCGC","TGATGGTGG","CGAGCGCCT","AGCTCAGTT","TCTATCCAG","TCGGTTCAA","TTTGGGTAT","GGGGGACTT","GTTCGAGTC","CCGAGCCGG","GAGGGGGGG","TCATCCGGC","GCGAGGGGG","GTTCAAATC","GTGCCGAAC","GTGCTTCTT","AAGCCGCCG","GCTGAGCTA","CCCCTCCAA","GCGAAAGTG","GCAACGCTC","CCGCTCACT","CGCAAGCGT","TCCGACCTA","GTCATTCAT","ATATTGGTG","ATCCTTCCC","TCCACCCCG","CCCACCAAT","TATAAAATA","CGCCTGATG","CGAAAAAAA","AGAAAGCGG","CCCCCGGTG","GCGGTGAGG","CCGTCATCA","AGACGCATA","AGCGCGTCT","CTTAACGCG","TCCGGCCTA","GGTAGAGCA","AGACGCATT","GCGGCGCGA","TGATTTTGT","GTTGGTAGA","CCAAAGCGC","TAAGGCACT","GTGGGTCAA","TTGCCGTTA","ACGCTTAAC","GGTCGGATA","GTTCACGGT","AAAAGCGGC","CTACCAATT","CCCCGCTGG","TTTTGGGTA","TTCGAACCT","GGGGTCGGC","TCGCATCAG","GGCAGAATA","TACCAATTC","GCCGGTATC","GCAATCAAT","AGGTTTTCC","CGACCCACC","TGCACCTTT","GAAGGATTA","GGAGCAGCC","ACGCCGCAT","TCGAATCCT","AATATCAGC","TTGAACCCC","CAGAAAAAG","TTGCGGCAC","TGGACAGTC","GCCAGACAG","CGCTTTGTT","ACTTATCAG","CGTCGGTTC","CGCTTAACG","CCAGTTCCA","TCACTGCGT","ATGCGCTTT","GCCAAAGCG","CGACATCCA","TTAGCGTCG","AGTTGGCGC","TCGCAGGTT","TCCTGCACG","CTGAAGCTA","TCAAAAGTT","CCTACATGT","CAGACAGCG","CATGCCTAC","CTGGCTGGC","CGCCCTACA","TTGTAGGCC","TATTGGTGA","CGACTGCCG","AAGCTAGCG","ATCTGTAGG","CCAGCTCTT","CGTCATCAC","CCCCCGCAA","ATCCCCGCT","CAGTCGGCA","TTAGCTCAG","GTTCACGCC","AACCGGTTG","ACATCCAAC","TAAACGCCT","TCTTCTTTA","CGACATCAA","TCTCATCCC","ACCCCCACG","CAAGCTGGA","AGCAGCCTG","CCCGGTTTA","TAAGATGCG","CACCGCTGT","ACCCACCAA","CATCCTTCC","GGTGCCTTA","TCAATTGGT","GTTTATCCC","TTTGCTTAT","TTACCGCTT","TAATGCGGA","TGCGCACGA","GGATAAGAT","AAGACGCAT","TCTACCAAT","GCTGGGGTA","TGGCGGATG","AGCCGCAAC","TGAACGCCT","AAGACGCAC","CTTTTGGGT","GTAGGTCGG","GTCGCCAGT","TAATCAATT","GTTTGTAGG","TCGGTTCGT","CCGGATAAG","GGATAAGAC","TAACACCTG","GCGGTTCGA","CAGCCACAA","CGTCGGGCT","GAACCTCCG","GACGCACAG","TCCAGCTGA","CCACCTTCG","ATTTAGCGT","GTGCGAGGG","TGATTAGCT","CTACGGAGG","AATGATGAA","GGAACAGCA","TGTAGGTCG","AAGACGCGT","CCGAAGCGG","TGGCGCACA","ATCAACGCC","GCGCTGCGC","ATCCGACAT","CCGTAGGTC","CCGGTGCCT","TCTGTCCAA","AAGACGCGC","GTGATTTTG","CGAAGCTTC","CTGTCGCGT","TTATCATGC","ACGCCAGAC","TCGTTAGCT","TGCGGCAAC","GTGGACAGT","GCTTCTCAT","TCTTTAAAT","GTTCGATCC","AAACGCCTT","GAAGCTAGC","TGCGGGAAT","ATCCGACAA","CCGCCGTCG","ATAAGATGC","CGCGCTTCG","TTAAATAAT","ATCGGGAAA","ATCCGACCT","TCGGATGCG","CACGCTGCC","GCACGACCC","ACCCACCAC","TCCCGTCAT","TCGCGAGTT","GGCAATCAA","AACTGTAGG","GGTGATGTT","GCTCTCTCG","GCACGACCT","TCTCATCCT","TTTCTGCCC","ATCCGGGAG","GCGGGGAAC","CTTACCGCT","ACAGGTCGA","TCCGGCAAT","GGGTTTTTA","CGCATCAGG","AAAAATGAT","CAATCAATG","ACGACGCGG","TTGACTCGC","GCTCACTGC","GGTGGGTCA","CGGGAATAG","GTCCGTAAG","TGCGGCACT","TACTCAGCG","CCGCTGTGA","GGGGATTGA","TCATCCCCC","ACGCCTTAT","GCAGAGAAG","CGCAAGCTG","CTCGCCCTG","GTGTGCAAT","CGACCTTGC","GGAAGGATT","GCCCTGCGG","CGCTCGGTT","TTACGTAAA","GCGCTGCTC","GGATAAGGC","GTAAACGCC","GTGATGGTG","GCTCATAAC","TCAAATCCG","CGCTCGCCC","ATCCGGCCC","TGCATCCGG","CCTGGCGCT","GGCGCAGGC","GGGAGGATT","GGGAAGGAT","TGCATAATC","CCGACCGCT","ATCCGGCCT","ACCGTGCTG","CAACAACCG","CTGCGGGCA","CTACGGTTA","CACCCCGTA","CGCCAGCAG","GAAGCTTCT","CGTTAGCGT","TGAACTGTA","CGTTTCCCG","TTTTAATCA","TACGCGTCG","GCGCTTTGC","CTCGTTTCC","AATCAATGC","TCACGCCGC","AAAAGCCCG","AAGCCGCTA","TGCCGACCT","ACTATGGCA","CCCCCACGT","ACGATATTA","TTAACGCGT","AAGCCGCTT","CAAATCAAC","AGCTCAGCT","GCAGCTCCG","AGGAGGGGG","AGTTGACTT","GGTAAAGTG","CCCTTCGGG","CCAAGGTCG","CCGCTGTTC","AGTGATGGT","TCTTTCTGC","AGGTCGTCG","GGTTCGAAT","CTTACAAGG","TGAAAGTGA","CGATCCCGT","GGTCAAAAG","TGGCGCGGG","GTCGCGTCT","CTATCCAGC","ACGCATAGC","TAAGAGATG","GACGCGCAA","GACTCGCTT","GATCAGCAC","CGCGTCGCA","AGAGCAGTT","CGCCGCGCC","AGGCATTTG","AAAAAAGCC","CCAGTTGTC","GGCGTGAAC","TTATCAAAA","ACGCGCAAG","GTAGAGCAC","AATCAATTG","GATACCGCT","AAGTTGCCG","GGATTACTC","CGCTGACGC","CGCAACCAA","TCCGACCGC","TTGGCGATA","CACTGAACT","GTAGAGCAG","GCAGTTGAC","GAACCCCCA","CGCTTTGCT","CGAGCCGGT","AGACGCACA","CCCCGTAGG","ACAATGCCT","GAGGGTGCG","GCGGGGTGG","GACTTGAAC","ACTTTCGTA","TTATTGCGG","AACGGCTGT","GCGCGAGCG","ACGGATGGC","GGATGCATC","ATGGTGCAT","GCGTGATTT","TCAGCAGCC","GGGGGATTG","GTTGCCGGA","CGCCGTCGA","CGGGGAACT","CACGTCCGT","ATCCAGCGT","TAAGCGTAG","TCGGGCTCA","AGAAAAAGC","GTACTCTAT","TATGCCGCA","CGGGGAACA","GTCGTGGAC","TGATGCGAC","CGCTGTGAA","ATTGGTCGC","CCGCTACTA","TGGGTATAG","TGGTAGCTC","CCGCGCAAA","GGAGAGCAC","ACAAACGCA","ATCCCGTCA","AAGCAGAAG","TATCCGACC","TTTAATCAA","GCGATACCC","TTTACGTAA","CGGCGTAAA","ATGCCGCAT","GGGCAGCCC","TTAGCGTGA","CAGCAGCCG","TCCCCGCTG","AAATCGCAG","GATAAGACG","TGCACGACC","GGTTACGCC","AGTTCGAGT","TCGCATCCG","ATATCAGCA","TTGTAGGTC","CAGGTGAAA","CATTATTGC","GGCACCGTT","TGATGCGCC","TCAACGCCT","AGGAGTTAA","TTTGAAAGT","ATGATGAAA","GCGTCTACC","TGGGAGAGC","ACGGATGCA","GCTTTGCTT","ACGCACAGC","CTGAACTGT","GGCGCACAA","AGCAGCCGC","CCCTACATG","TTATCCGCC","TACGGATGC","CCCACCACT","TATCAGCAG","CGCCAGTTG","CAGCAGCAA","TACGGATGG","CGAAGGTCG","CGGAGGGTG","TTGGCAACA","CCGCAACCA","TGCTTCTTC","GACATTATT","CCCCGCAAC","CTGCAGCTG","GATGCGACG","TTAAATATG","TATCCAGCG","GAGGATTCG","TGACTCGCT","AACCCCCAC","CGGGAATTT","GTCGGCACC","TATCCAGCT","CGCAGGTTC","AGTACTCTA","TGAACCCCC","GTGATTAGC","AGAGCACCT","CCAATTCCG","CGGTTATGT","GAAGTGCTC","AGAGCACGA","TTGCCGACC","AAGCGCGCA","ATCCGGCAG","CAACTGGCT","ATCCGGCAA","CTGATGCGC","GAAGAGATC","GCAGCCGCA","CTACGCCAG","GAGCAGTTG","GCAGAATAT","GAAAAAGCC","TTCGAGTCT","CAGCTCCGG","TCTTATCAT","CGCACGACT","GACCTTGCC","CATCTTTCT","ACGCGTTAG","CTGATGCGA","ACCTGAAGC","TCTCGTTTC","GCACGACTG","GCCCGCTCA","CTCAGCTGG","TCTTATCAG","CGTCTACCA","AACCCGAAG","ATAAGCGTA","GAAAGCCAG","ACGACCCAC","CGTGGACAG","TACGCCGCA","ACGCATTAC","CCCCGGTCG","AAGCGTAGC","ACGCCTGAT","CTGCTGAAA","GACCGCTCG","GTCTGCTTC","GCGGGCAGC","GACCTTTCG","CCGTAGGCC","CGAGCTCTT","GTCATCACC","ATCAGCAGC","AAGAAAGCG","CCGAGTACT","GCGTGAACG","TGATAAGCG","GACGCATAG","CGTAGCCGA","ACTCAGCGC","CCTGCACGA","TTGACTTTT","GCAACAGGC","CCCGGACGG","AGGATTACT","CCGTACTTT","CAGCAACAG","GAAATGATG","GGCGGATGC","TTCAATATT","CGCTGTAAT","CGGGTCGTT","CGCCCTTCG","CATCCTGCA","GTACGAGCT","TCTTTTGGG","GTTGCCGTT","TACTAAAGC","CGCCTTATC","AAAGCGGCT","TCATCCTTC","CGAAGTTGA","GACATCCAA","CTGGAACAG","AAAGCCGCC","AAGAGATGG","CGGATACGG","ACCGCTTGG","TCATTCATC","AACCAGCAG","TGAAGCTAG","CTATTGCCC","GCTGGAACA","TACGGGGTG","GAGCTACGG","GTGATCGTG","GGCGATACC","GTTACGCCG","AGGCGTTTA","AAAGCGGCA","TCGCTTCGC","ATTGCGGCA","CGGGGTCGC","CCCCGGTGT","CGCCGAAGC","GCTCCACCC","CTCAGCGCT","ACTGTAGGT","ACTGACCGA","AGCGCATCA","CAGTTCCAG","ATAAAATAT","GATTAGCTC","CCGGGAGGA","CCGGCAATC","GCCCCTCCA","TGCACTGAA","ACTGTAGGC","ACACCTGAA","GCTAATGCG","CCGGTGTGT","CCGAAGGTC","CGACATTAT","ACCTCCGAC","GGGAGAGCA","GCGGACTGA","CGCACAATG","TTCACGACG","ATTGCGGAT","TGATGAAGC","AAAATCGCA","AGTTGCCGT","CTAATGCGG","CGACGCTTG","GCGCAAAGC","TTGGTAGAG","CAACCGATG","GCGCACGAC","TCTGCCCCT","GGGTGCGGG","TGATAAGAC","CCCCACGTC","GAAAAAAAA","CATCCGGCA","AGCAGAAGC","GCCTGGTAG","GAACTGTAG","CCCTCCAAA","GGAGTTTGG","TTATGTTCC","CGACGCTTA","GCGGATTCG","GTCAAAAGT","TCCGCCCTA","ATCAGGCAT","CGGCGGCGG","GCCGCTATT","TATGTTCCG","TGACTTTTA","ATTCCGCCA","GGACTTGAA","CTTCTTTAA","ATCAATTGG","GCGGCGTGA","ATTGACTCG","TTTCGTACG","TTCGTAGCC","CGTTGCTGC","AGCTGGATG","AGCGGGTTT","ATCAGGCAG","AGGTTCGAA","ATCAGGCAA","CATCAACGC","ATGGCACTA","CTTCCCCGC","TGTCGCGTC","TCGTTTCCC","GTCGGTTCA","TGGGGGAAG","AGCACGACC","ATCAGGCCT","AGGGGGTCG","TGGCGATAC","GCCGCATCC","CCGGTTTAT","GCTGGCGCG","TGGCAATGG","CGTTAGCTC","AGAACAGGT","GTCGCGAGT","CCGACCTAC","AGGCACTTG","TTCGAATCC","AGGTCGATC","GCCTGATGC","CCCGTCATC","TGGGCAGAA","CACAATGCC","CGATAAGCC","GTAGCGCAT","CGACGCTGT","CGACGCGGC","TGAAGTGCT","CGACGCTGG","TCTCACTCC","CATCCGGGA","AAACTGACC","GCAGCCTGG","CTCGTCGGG","TGTCGCCAG","CTTTCTGCC","ACGCTGGCG","GCTGGCGAT","GTCGAAGCT","CCGACCTGT","CGCTTGGCG","TCATCCTGC","TCATCCTGA","TTTATGCCG","GCCTGATAA","CAACAGGCT","GTCGAAGCC","TAGCCGAGT","GGGGACTTG","CGGCAACGC","TGATGAAAT","TCACCCACC","GCTGCCGGA","ATCATGCCT","ATCAGCACC","AATCGCAGC","GACCTACGG","CCAGACAGC","ATAACCCGA","GACGCTGTC","TTTATCCCC","CGCCACCTT","AAGTGCTCC","TTAAATGAT","ACGCTCTTT","CTTCTCATC","AAATGATGA","TAGGCCTGA","GGGGGGATT","CCGGCCCCC","GCGCTACGG","GAAGAAAGC","CGGACGGTG","ACGGCTGCC","CAGGCATTT","ATGGCGGTG","GGCTGTCGC","GTCCAACTG","CTCTCGCTG","GTTCGCCAC","GGGTCGTTG","CAGAAGCAG","GGCGTTTAT","ACCGCTCGG","GGGTCGTTA","ACGACCTTG","CTGTAGGCC","GCGCCGCTG","TGCATCGGG","GCCGCAACA","TCGAACCCC","GCTCGCCCT","CTACAAAAT","CTGGTAGCT","GATCGGTTC","GCCCTACAT","CCTGATGCG","GCCTACGGA","TGCTCCACC","CGGTTACGC","GTTATGTTC","GCAGTTGGC","CTTATCAGG","ATCCAGCTG","ATAAGGCAC","GGAGTTAAG","GCCTACGGG","CACCAGCGC","GGAGTTAAA","AATTGGTCG","CGAACCTCC","TTTAGCGTG","GGCACTGGA","GTGCCGCAT","TTCGATCCC","GGCGGTTAC","GGCTCATAA","CAGGCTAAT","CAGTTGACT","CGGATGGCG","ACCGCTGTG","GACGCTGGC","GGTGGAGCA","CCGTTGCCG","TAGCTCGTC","CGCCCTGCG","CGCGGGGTG","GGTCGTCGG","TGCGGGCAG","GCGACTTAT","ACCTTGCCA","AATCCGGCC","GTGAAGTGC","CACTGGAGT","TAGGCCGGA","AGCTTCTCA","ACCTGTAGG","GAGTCTCGT","GGCGGTTCG","CATCTGCGC","GGCTGCCGG","GCAGAAAAA","TGCGAGGGG","GCGGATGCG","TATCATGCC","TGAAAGAAG","CGGATGCGG","AAAGAAGCT","TGCAGCTGA","GTCGCAGGT","AAAGCCCGT","ATAGCTCAG","GCGCAATAG","GCGCTGGAA","GCCTACGCC","TAGGGCAGA","ATTACGCGT","CGGATGCGC","CGCGTCTAC","CCGCTTGGC","GACCTGTAG","GCCAGCCAC","GGGACTTGA","CGTAGCGCA","CGGCGGTTC","AGGCGTTCA","GCGTTTATG","GATGCGGCG","GAATTTGTA","CTGGCGCAG","GACAGCGCA","CATTCTGAT","TTCGTACGA","TGTTCATAT","CCGGTTGCC","CGTCGCATC","AGGCGGTTA","CCTGATAAG","ATCAGGCGT","ATCTGCGCA","ACTTGAACC","CCGGTTGCG","TGTGTGCAA","CGGTCGGGG","ATAAGGCGT","CAGGTCGAT","CCGCCCTAC","TAAGACGCA","ATAAGGCGG","TAAGACGCG","CGCACAGCG","CGTGCTTCT","TTTTTACGT","GAAACTGAC","AGCGTCGCA","GCGCTGGCG","GACGGTGCT","GGTGTGTGC","TAGCGCATC","CCTACACCG","TCAATATTG","GATACGGGC","GCATAGCGT","GCTATAGCC","AAAACCCGC","AGATGCGCA","AGCAACAGG","ATATGGCGG","TATCCGGCC","CTTGGCGAT","GCAAGCGTC","GAATAGCTC","GGGTGATTA","GGCAACGGC","GAGAGCACC","CGCTTTCTT","GAGGGGGTC","GGAGGGTGC","TGGTGGTGG","GGGAATTTG","ATGCCTGAT","ACATCAACG","CGCTACTAA","ATATTAATA","TCCGGTTAA","CAAAAGTTG","CTCTCTCGC","GCTGATTGC","CGCTATTGC","CCTGTAGGC","AGATGGTGC","ACTGCCGGA","CCTCCAAAA","TACTCTATC","CGCTCTCTC","CGGCACTGG","TGCGACGCT","GCTTATCCG","TTGGCGCAC","GCAGCCACA","TACGCCAGA","TTACTCAGC","CAGGTTCGA","ATCCTGCAC","GGGGTGGAG","TCCGCGCAA","GGTTCGTAG","AGCGCACCA","CTGATAAGC","CTGATAAGA","CGCGCAAGC","ATTCGAACC","CTGCGCCTG","CGGCGCGAG","GGGTCAAAA","CAACGCTCT","AATTTGTAG","AAGGCGTTT","CGCTCCAAA","TGCTTATCC","TCATCTTTC","ACGCTCTCT","AGGGGGGGA","CGTTGCCTG","GGCAACGCT","CGTGATCGT","CTCTTCTTT","ACCGATGCC","CATCAGGCG","TTTATCGCC","TAAATATGG","TCAGCGCCT","AGAGATGGT","CATCAGGCA","TCCCTTACA","AGACGCGCA","CATCCAACG","CCCGCTGGC","CCGACAACC","GCCTTATCC","TGAATCAGC","AAGGCGTTC","CATCGGGAA","GCAGTCGGC","CGCGCAAAG","GGGGGGACT","AAGGAGGGG","AATGGCGCT","CGGATGCAT","AGGGGGGGG","CGCGTTAGC","TCAGGCCTA","GCGACCAGC","TCGGCATCG","TTGCCGGAT","CTGGCGCGT","CGACCTACG","CAATATTGG","CCTTCCCCG","AAGCGGCTG","AAGCGGGTT","TTACAAGGA","CTTATCATG","CTAACACCT","CGTACTTTC","CTGGCGCGG","GTGCATCCG","TCAGGCGTT","CGCGACTTA","TCCGGGAGG","ATACAGCGA","ACAGTCATT","GGCAGTTGG","CGAGGGGGG","CCGCTCCAA","TGCCGAACC","CCCGCTCAC","GTGGTGGGG","GGCGCGTCT","CGTAAACGC","TGCGGATTC","GAAGCCGCT","AAGCCCGTA","GCATCTGCG","GATGAAATG","GCACCTCCC","CTGGCGCTG","GTTAGCGTC","ATCTTCTTC","GTCGTTAGC","GCTCAGCTG","GCCAGTTGT","GGGCAGAAT","GCTAGCGCG","TAGAGCACG","ATGAAATGA","TCGAACCTT","GCATCGGGA","CCACCTCTT","CTGAGCTAC","CTGACGCGA","TCGAACCTC","ATCCGCCCT","ACTTGTGCC","AGCTCGTCG","GCCCGTACT","TATTGCCCG","AGCGGTTGA","AGCTAGCGC","TTTTGTAGG","GTGCGGGAA","GCTCGGTTC","CACCGTTGC","CGCATTACG","TATGGCACT","CGGGGTGGA","ACTAAAGCC","GGGAATAGC","CTTTTGAAA","ACAACCGAT","TACGGTTAT","CGGCGTGAA","GAGCGCCTT","GGATTCGAA","GATAAGCGT","CCGAACCGT","GCGGGAATT","AGCACCTCC","GGTCGCAGG","CGGCCCCCG","CCTTCGGGT","GGGGAACTC","CTTCGCCCT","GCTGCTGAA","GTTCGAATC","CAGCGTCGC","GATGCGCAA","AGCCGCCGT","TAAGGCGTT","TGACCGATA","CCTTACCGC","TGGGTCAAA","CGACTTATC","TATGGATTA","GGCACTTGT","GCGGGAATA","CTGCCCCTC","TAGAGCAGT","TTGAAGTTG","GTCGTCGGT","AGCGCCTTA","CTCAGTTGG","ACAAGGAGG","CGCAACAAC","CTGCCAGCG","GCTGCTGCT","CCCGCAACC","GTTAGCTCA","TACACCGCT","GCGGTTACG","AAAAGTTGC","GCGCATCAG","GGTGCTACC","GGGGGAAGG","CCCGTACTT","CCCGCTCCA","AGCTCTTCT","TGGCGGTGA","TTGGTCGCA","TGATTTAGC","AGGCCTGAT","CGACCGCTC","GGACAGTCA","ATTATTGCG","AGTTAAATA","GCGGCGGCG","CGCATCCGG","GATGCGCCG","GTACTTTCG","TCTCCGTTC","GGTGGTGGG","CACGACGTT","CGCATCCGA","AGCCGGTTG","ACCGGTTGC","GCAGGTTCG","TCCAGACGA","CGCCGCTGA","TGTCGTGGA","GGGGGTCGG","AACAGCACG","AGTTGTCGA","CCCCCCGGT","GCTTTCTTT","CAGGCAGTC","CAACGGCTG","GCGGGTTTT","CTGGGGTAC","ACAGCAACA","CCACCAGCA","GAGTTCGAG","TTCGGGTCG","GCCAGCAGG","AGCGTGATT","ACAGGCTAA","GCCAGCAGC","CTGATTTAG","CACCTGAAG","AAAAAAAAG","CGACAACCG","CGGCCTACG","GCTGTCGCG","GCTATTGCC","CGGCCTACA","CCACGTCCG","GCTGTCGCC","AATCTGGCA","AGCGCTGCG","CAATGCCTG","AAGCGGCAG","AACGCCTGA","ACGGAGGGT","AACAGCAAC","ATATGGATT","GCGCACAAT","GGGTGGAGC","GGCGTTCAC","TCCGACATC","CGAGTACTC","GATTGCCGA","TGCTGAAAC","CAGCCTGGT","TATCCGCCC","AAATAATCT","TGCTGAAAA","CCTTGCCAA","GAAAGAAGC","TCCGACATT","TGGCAACAG","GCCGCCGCC","GGTGATTAG","CGTTGCCGG","CAAGGAGGG","GCCGAGTAC","AGACAGCGC","GCTACTAAA","TCTGCGCAC","GCTCGTCGG","CAAGCGTCG","CGGTCTGTC","TGGAGTTTG","GAGCACGAC","TCGTACGAG","CTCCGACCG","CGGCAATCA","TGCCGCATC","AGCTGGGAG","AGCTGAGCT","CTCATCCCC","GATCCCGTC","TGGTCGCAG","CTCCCTTAC","CGTACGAGC","GAATCCTGC","ATACCGCTA","CGCGGGGAA","CGCGTCTGC","AATGCCAGC","CGCTTCGCC","CGGGAGGAT","AGGCCGGAT","CGCTTCGCT","GGTCTGTCC","TAAATATTG","GACTTATCA","TCCGGCCCC","AGAATCTGT","CTTGTGCCG","TCAGCGCTG","CCCTGCGGG","CAGCTGGGA","GGAGGGGGT","AGGCATCTG","TACAAGGAG","GGTTCAAAT","TTCTTTAAA","TTCCCGCTC","CTTCGGGTC","CAACGCCTG","TAGGTCGGA","AATATTGGT","CTTATCCGG","GACGCTTAA","CGGTGAGGG","GAAAGTGAT","GATGCCTGA","CTTATCCGC","GATCCGCGC","GAGTACTCT","GGTCGTTAG","TCCAACTGG","CTCGCTTCG","CGGCGCTGG","CTACATGTG","TTCCGCCAC","TTGGGTATA","TGGTAGAGC","GCATCCGAC","GCGGTTTAT","AGACGCGTT","GCAATAGCC","CCTCCGACC","CGAGTTCGA","ACGAGCTCT","CGCAAAGCC","GCATCCGGG","GCGGCGTAA","GCTTGGCGA","CGATACCCC","CATCCCCCC","GGATACGGG","GTCGGGGCT","CGCTGGTGG","GGCACTATG","GGTTGCGCC","GCATCCGGC","GCGTTAGCG","GTCACCATT","GGCCTACGG","GGCCTACGA","TGATACCGC","GGCCTACGC","ATCCGCGCA","AAAGCGGTT","GGTCGGCGG","GGTCGGGGT","GGCCGGATA","CGTTCACGC","AGCCCGTAC","TAAGGCGGT","TGATAAAAA","GAGTTAAAT","CGTTCACGG","GAAAGCGGC","CCTTATCCG","GGTCGGGGC","CCCGCCGAA","GCGCGTCTA","GACAGTCAT","GCGCCAGTT","TAGCGTGAT","GGTGCGGGA","CAGCACGCC","GCGTCGCAT","GCGCGTCTG","GCATTACGC","TCGCCAGTT","AACGCTCTC","GGCTGGCGT","CCGGTCGGG","GCGCGTCTT","CCGCTGACG","CGAGTCATC","AAAGCGCGC","ACTTTTAAT","TTGCGGATT","CTGGCAGTC","CGGTTCAAA","ACGGTGCTA","CTGGCGGAT","CCTGATTTA","GACGCGACT","CTGGCAGTT","AGCGCAATA","CGAACCGTA","GCCGGATAA","ACCGTTGCC","AGTCATTCA","TGGAGCAGC","TGATCCAGT","GCCGACCTG","GAGTTTGGC","AAGCTGGAA","GAATGCCGG","GTCGGCGGT","CGGTGCCTT","AGAAGAACA","CAAGGTCGG","GCCGAAGCG","GTTAAATAA","TCGGGGCTT","CGCTACGGC","CCGCTCGGT","TACTTTCGT","CTTTCGTAC","GCTGGGAGA","GCACTTGTG","ATGCGCAAG","GGTCGTTGC","AGCTCCGGC","AGTCTCGTT","GCCGGATGC","CGCTGAAAG","TTGCCAAGG","CTGGCGGCG","CTGGCGGCA","CAAATCCGG","TAAGCCGCT","GACGCATTA","ATTCTGGTG","TACAAAATC","CCGATGCCT","CCTCCCTTA","GCACAGCGT","TAGCGTCGC","GCCGAACCG","TGCGCCGCT","GCCGGTTGC","CTTGAACCC","CCAGAAGAA","GGATTGACT","AATCTGTAG","ATGCGGCGC","GATTTTGTA","GACTTTTAA","CTGCTCCCT","CGCCAGACA","CACCCACCA","CTGTCCAAC","ACCCGAAGG","ATGCGGCGT","AACCTCCGA","GATGCGCTT","CTACGGGGT","AAGGCGGTT","GTTGACGGC","CACGACTGC","TCGCTCGCC","TCATGCCTA","GGGATTGAC","ACCTCCCTT","TTGCCGCCG","TCCCCCCGG","TTCTCATCC","GCAACCAAT","GATAAGCCG","GCTGCAGCT","ATGCGCCGC","TCAGGAGTT","AGCGCGCAA","TGAGGGGGG","CATCCGACA","CTAGCGCGT","TCCGACAAC","CTTCGCTCG","TTGTGCCGC","GGCTAATGC","CAGCGCTGC","ACGACGTTC","TAACGCGTC","CTTTTAATC","GATAAGGCG","ATGAAGCAA","TGCCTGCGG","CGCTGCGCG","CAAAGCCGC","CGGTTTATC","TGAAATGAT","CGCACCAAA","GATAAGGCA","AAGTTGAAG","CGCGTCTTA","AAAGTTGCC","GCACTGGAG","ACGGTTATG","ACGCGTCGC","GGCCTACAA","AGCTGGAAC","TGATGTTGC","CCGGCAGTT","AACAGGCTA","GGCCTACAC","ATTCATCTT","CTACCGCTA","GCCGCCGTC","CGGGGCTTC","ACTAACACC","GCTGCTGGC","GCCGCTTTC","GCTACCGCT","GCCTGATTT","AGCCTGGTA","CTTTCTTTT","TTTTACGTA","GATGGTGGT","ACGCTGTCG","GTCGTTGCC","ACAGCGCAA","GTCTACCAA","CTGTAGGTC","ATCAATGCC","TCGTTGCCT","AAAAACCCG","GCACCGTTG","CGTCCGTAA","AAGCGGTTG","CACCTCCCT","GCTGGCTGG","GCGCAAGCG","TCGTCGGTT","CTGTGAAGT","CGGGCAGCC","GCAAGCTGG","CCTGGTAGC","CAGGCATCT","AAAGTGATG","CTGACCGAT","ACTGGCTGT","TTGCTTATC","GGTTATGTT","ACCCGCCGA","TCAGCTGGG","TGTGAAGTG","TATTGCGGC","TTCGCTCGC","GCGGCACTG","GGGCTTCTC","ACCAATTCC","CGGTGTGTG","GCTTAACGC","AACAACCGG","GGCGCGAGC","CATTCATCT","AACACCTGA","GTTTCCCGC","AGCAGTTGA","ACCCCGTAG","GAGCCGGTT","CAGTCATTC","TCGGCGGTT","GAAGTTGAA","GTGAAACTG","CCACCCCGT","CAATATCAG","AACTGACCG","AAATGGCGA","CACGCCGCA","CAAAATCGC","AAATGGCGC","GATGGTGCA","TGCGCCTGT","AAATGGCGG","ACTCGCTTC","CTGCGCGCT","AACGCCTTA","CATAGCGTC","GTGCTCCAC","GCGTTCACG"};

		for (int i=0; i<data.length; i++) {			
			Set<Integer> set = gnp.showLocation("datasource/E-coli.txt", data[i]);
			System.out.println(data[i] + " : " +set);
			Object[] intArray = set.toArray();
			if (intArray.length>1) {
				for (int j=0; j<intArray.length-1; j++) {
					if ((Integer)intArray[j+1]-(Integer)intArray[j] <= 500)
						System.out.print(intArray[j]+"-"+intArray[j+1]+",");						
				}								
			}
			System.out.println();
		}
*/		

		
		
	}

	private Set<Integer> showLocation(String fileName, String pattern) {
		Set<Integer> result = new TreeSet<Integer>();
		InputStream is = null;
		Reader buffer = null;
		try {
			if (fileName!=null && pattern!=null) {
				
				is 					= new FileInputStream(new File(fileName));
				Reader reader 		= new InputStreamReader(is, Charset.defaultCharset());								
				buffer 				= new BufferedReader(reader);

				int patternLength 	= pattern.length();
				char[] genomeSlice 	= new char[patternLength];
				
				// Initialization
				if (buffer.read(genomeSlice,0,patternLength)==patternLength) {
					long offset = 0;
					if (match(pattern, genomeSlice, 0))
						System.out.print("0 ");
					
					int ch =0;
					while ((ch = buffer.read()) != -1) {
						// replace
						genomeSlice[(int)(offset%patternLength)]=(char)ch;
						// advance
						offset++;
						//match
						if(match(pattern, genomeSlice, (int)(offset%patternLength)))
							result.add((int)offset);
							//System.out.print(offset+" ");
							


					}
					
				}

			}
		} catch (IOException e) {
			e.printStackTrace();
		}		
		
		finally {
			try {
				if (is!=null)
					is.close();
				if (buffer!=null)
					buffer.close();				
			} catch(IOException e) {
				e.printStackTrace();
			}
		}		
		return result;
	}
	
	
	private boolean match(String pattern, char[] slice, int offset) {
		boolean result = true;
		//if (pattern==null || slice==null)
		//	return false;

		int patternLength = pattern.length();		
		for (int i=0; i<patternLength; i++) {
			// circular
			if (pattern.charAt(i)!=slice[(i + offset)%patternLength])
				return false;
		}
		
		return result;
	}
	
}
